package com.example.myapplication;


import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

import android.app.DatePickerDialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.app.Service;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Gravity;
import android.view.View;
import android.widget.DatePicker;
import android.widget.ScrollView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;

public class MainActivityone extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);

        //第一步，取到通知管理器
        NotificationManager notificationManager = (NotificationManager)
                getSystemService(Service.NOTIFICATION_SERVICE);
        //第二步，创建一个通知渠道（Android 8）
        Notification.Builder builder;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            //android 8.0以上需要创建一个通知渠道
            NotificationChannel channel = new NotificationChannel("2041", "自定义的通知渠道",
                    NotificationManager.IMPORTANCE_HIGH);
            channel.enableLights(true);
            channel.enableVibration(true);
            channel.setShowBadge(true);
            notificationManager.createNotificationChannel(channel);
            builder = new Notification.Builder(this, "2041");
        } else {
            builder = new Notification.Builder(this);
        }

        //第三步：构建具体的通知并显示在系统上
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentTitle("这是通知的标题");
        builder.setContentText("这是通知的文本");
        builder.setAutoCancel(true);
        //测试点击回调事件是否生效，此处为测试代码 不保证在所有机型都可以正常运行
        Intent intent =new Intent (this,MyBroad.class);
        PendingIntent pen =PendingIntent.getBroadcast(this, 0, intent, 0);
        builder.setContentIntent(pen);
        Notification notification=builder.build();
        notificationManager.notify("tag", 1, builder.build());

    }

}
